package com.efesco.finance.gathering;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.view.data.ViewBaseField;
import com.bstek.dorado.common.*;
import com.efesco.common.Tools;

/**
 * inputGatheringDetail_invoiceInfoDatasetListener
 */
public class inputGatheringDetail_invoiceInfoDatasetListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset)
     throws Exception {
	DoradoContext context = DoradoContext.getContext();
	String hrInvoiceDetailId = Tools.toStr((String) context.getParameter("HR_INVOICE_DETAIL_ID"));
	String preMonth = Tools.toStr((String) context.getParameter("PRE_MONTH"));
	String sql="";	
	
	if (preMonth.equals("")) {
		sql = "select cmp.company_chinese_name,i.invoice_code,i.invoice_amount,i.invoice_date,i.arrive_amount,i.arrive_date,o.ought_receive_id," +
				"i.invoice_id,to_char(i.input_date,'yyyymmdd') input_date,i.payment_type,i.if_effect,h.ought_month,o.ought_amount,o.payment_version_id,"+
				"h.gathering_amount,h.rate_odds,h.gathering_memo,h.hr_invoice_detail_id,0 if_percent,h.payment_type oType "+
				"from s_invoice i,s_hr_invoice_detail h,s_single_company cmp,s_ought_receive o "+
				"where cmp.single_company_id=i.single_company_id and i.invoice_id=h.invoice_id "+
				"and  cmp.single_company_id=o.single_company_id and h.ought_month=o.ought_month "+
				"and o.payment_type=h.payment_type and o.pay_send_ids=h.pay_send_ids and h.hr_invoice_detail_id="+hrInvoiceDetailId;
	}
	else  {
		sql = "select cmp.company_chinese_name,i.invoice_code,i.invoice_amount,i.invoice_date,i.arrive_amount,i.arrive_date,o.ought_receive_id," +
				"i.invoice_id,to_char(i.input_date,'yyyymmdd') input_date,i.payment_type,i.if_effect,h.ought_month,o.ought_amount,o.payment_version_id,"+
				"h.gathering_amount,h.rate_odds,h.gathering_memo,h.hr_invoice_detail_id,0 if_percent,h.payment_type oType "+
				"from s_invoice i,s_hr_invoice_detail h,s_single_company cmp,s_ought_receive o "+
				"where cmp.single_company_id=i.single_company_id and i.invoice_id=h.invoice_id "+
				"and  cmp.single_company_id=o.single_company_id and h.pre_month=o.ought_month "+
				"and o.payment_type=h.payment_type and o.pay_send_ids=h.pay_send_ids and h.hr_invoice_detail_id="+hrInvoiceDetailId;
	}
	SqlDataset ivcDataset = (SqlDataset)dataset;
	ivcDataset.setSql(sql);
    return true;
  }

}
